package com.ruoyi.docdraw.service.impl;

import java.util.List;

import com.ruoyi.common.constant.UserConstants;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.docdraw.mapper.SysSubProjectMapper;
import com.ruoyi.docdraw.domain.SysSubProject;
import com.ruoyi.docdraw.service.ISysSubProjectService;

/**
 * 项目子项目协作Service业务层处理
 * 
 * @author lvtian
 * @date 2025-04-14
 */
@Service
public class SysSubProjectServiceImpl implements ISysSubProjectService 
{
    @Autowired
    private SysSubProjectMapper sysSubProjectMapper;

    /**
     * 查询项目子项目协作
     * 
     * @param subProjectId 项目子项目协作主键
     * @return 项目子项目协作
     */
    @Override
    public SysSubProject selectSysSubProjectBySubProjectId(Long subProjectId)
    {
        return sysSubProjectMapper.selectSysSubProjectBySubProjectId(subProjectId);
    }

    /**
     * 查询项目子项目协作列表
     * 
     * @param sysSubProject 项目子项目协作
     * @return 项目子项目协作
     */
    @Override
    public List<SysSubProject> selectSysSubProjectList(SysSubProject sysSubProject)
    {
        return sysSubProjectMapper.selectSysSubProjectList(sysSubProject);
    }

    /**
     * 新增项目子项目协作
     * 
     * @param sysSubProject 项目子项目协作
     * @return 结果
     */
    @Override
    public int insertSysSubProject(SysSubProject sysSubProject)
    {
        sysSubProject.setCreateTime(DateUtils.getNowDate());
        return sysSubProjectMapper.insertSysSubProject(sysSubProject);
    }

    /**
     * 修改项目子项目协作
     * 
     * @param sysSubProject 项目子项目协作
     * @return 结果
     */
    @Override
    public int updateSysSubProject(SysSubProject sysSubProject)
    {
        sysSubProject.setUpdateTime(DateUtils.getNowDate());
        return sysSubProjectMapper.updateSysSubProject(sysSubProject);
    }

    /**
     * 批量删除项目子项目协作
     * 
     * @param subProjectIds 需要删除的项目子项目协作主键
     * @return 结果
     */
    @Override
    public int deleteSysSubProjectBySubProjectIds(Long[] subProjectIds)
    {
        return sysSubProjectMapper.deleteSysSubProjectBySubProjectIds(subProjectIds);
    }

    /**
     * 删除项目子项目协作信息
     * 
     * @param subProjectId 项目子项目协作主键
     * @return 结果
     */
    @Override
    public int deleteSysSubProjectBySubProjectId(Long subProjectId)
    {
        return sysSubProjectMapper.deleteSysSubProjectBySubProjectId(subProjectId);
    }


    /**
     * 检查 项目的子项目名称是否重复
     * @param sysSubProject
     * @return
     */
    @Override
    public boolean checkSubProjectNameUnique(SysSubProject sysSubProject) {
        Long subProjectId = StringUtils.isNull(sysSubProject.getSubProjectId()) ? -1L : sysSubProject.getSubProjectId();
        SysSubProject info = sysSubProjectMapper.checkSubProjectNameUnique(sysSubProject.getSubProjectName(), sysSubProject.getProjectId());
        if (StringUtils.isNotNull(info) && info.getSubProjectId().longValue() != subProjectId.longValue())
        {
            return UserConstants.NOT_UNIQUE;
        }
        return UserConstants.UNIQUE;
    }
}
